package com.cidp.system.service.impl;

import java.util.List;

import com.cidp.system.dao.IRolePermissionDao;
import com.cidp.system.model.Trole;
import com.cidp.system.model.TrolePermission;
import com.cidp.system.service.IRolePermissionService;
import com.litt.core.common.Utility;
import com.litt.core.exception.BusiException;
import com.litt.core.page.IPageList;
import com.litt.core.page.PagePoParam;

public class RolePermissionService implements IRolePermissionService {
	
	private IRolePermissionDao rolepermissionDao;
	public void setRolepermissionDao(IRolePermissionDao rolepermissionDao) {
		this.rolepermissionDao = rolepermissionDao;
	}
	/**
     * 根据对象删除
     * @param TrolePermission 对象
     */
	public void delete(TrolePermission obj) throws BusiException {
		rolepermissionDao.deleteObject(obj);

	}
	/**
	 * 角色权限信息
	 * @param seNo 序号
	 * @return TrolePermission对象
	 */
	public TrolePermission load(Long seNo) throws BusiException {
		if(seNo==null && Utility.isEmpty(seNo.toString())){
			throw new BusiException("序号为空字段！");
		}
		return (TrolePermission)rolepermissionDao.loadObject(TrolePermission.class, seNo);
	}
	/**
     * 根据对象保存.
     * @param TrolePermission 对象
     * @return Long 主键值
     */
	public Long save(TrolePermission obj) throws BusiException {
		if(obj.getRoleId()==null && Utility.isEmpty(obj.getRoleId().toString())){
			throw new BusiException("角色ID不能为空！");
		}
		if(obj.getPermissionCode()==null && Utility.isEmpty(obj.getPermissionCode())){
			throw new BusiException("权限编号不能为空！");
		}
		return  rolepermissionDao.saveObject(obj);
	}
	/**
     * 根据对象更新
     * @param TrolePermission 对象
     */
	public void update(TrolePermission obj) throws BusiException {
		if(this.load(obj.getSerialNo())==null){
			throw new BusiException("不存在这条记录！");
		}
		if(obj.getRoleId()==null && Utility.isEmpty(obj.getRoleId().toString())){
			throw new BusiException("角色ID不能为空！");
		}
		if(obj.getPermissionCode()==null && Utility.isEmpty(obj.getPermissionCode())){
			throw new BusiException("权限编号不能为空！");
		}
		rolepermissionDao.updateObject(obj);
	}
	/**
	 * 加载集合
	 * @param id
	 * @return
	 * @throws BusiException
	 */
	public List loadPermissionById(Long id) throws BusiException{
		return rolepermissionDao.loadPermissionById(id);
	}
	public void deleteByIds(Long id) throws BusiException{
		rolepermissionDao.deleteByIds(id);
	}
}
